/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2022-03-31
 * Time: 21:13
 */
public class Accout {
    private String name;//户名
    private int accout;//账号
    private String password;//密码
    private double balance;//存款余额
    private int attempt=0;//尝试次数
    public Accout() {
        super();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAccout() {
        return accout;
    }

    public void setAccout(int accout) {
        this.accout = accout;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public Accout(String name, int accout, String password, double balance) {
        super();
        this.name = name;
        this.accout = accout;
        this.password = password;
        this.balance = balance;
    }

    @Override
    public String toString() {
        return "Accout{" +
                "name='" + name + '\'' +
                ", accout=" + accout +
                ", password='" + password + '\'' +
                '}';
    }
    //存款
    public void deposit(double n) {
        if(n>0)
            balance+=n;
    }
    //查询
    public void query() {
        System.out.println("你当前的账号余额为："+balance);
    }
    //取款
    public boolean withdraw(double n) throws BankingOperationException{
        if(n<=balance){
            balance-=n;
            System.out.println("取款成功");
            return true;
        }
        else
            throw new BankingOperationException("取款金额大与存款金额，取款失败");
    }
    //转账
    public boolean transfer(double n,Accout a) throws Exception{
        if(n<=balance){
            balance-=n;
            a.balance+=n;
            return true;
        }
        else
            throw new BankingOperationException("转账金额大于存款金额，转账失败");
    }
}
